import { AlertRefType, AlertType } from "../types";
import { MutableRefObject } from "react";

class AlertService {
  alertRef: MutableRefObject<AlertRefType> = null;

  setAlertRef(ref: MutableRefObject<AlertRefType>) {
    this.alertRef = ref;
  }

  showAlert(code: AlertType, message: string) {
    if (this.alertRef.current) {
      this.alertRef.current.show(code, message);
    } else {
      console.warn("Alert reference is not set.");
    }
  }

  hideAlert() {
    if (this.alertRef.current) {
      this.alertRef.current.hide();
    }
  }
}

export default new AlertService();
